package util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
   

    private static SessionFactory sessionFactory;

    private static ThreadLocal<Session> sessions = new ThreadLocal<Session>();

    static {
                sessionFactory =  new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();
                                
        }

    public static Session openSession() {


        if (sessions.get() != null) {
            }
                sessions.set(sessionFactory.openSession());
                return sessions.get();

        }

    public static void closeCurrentSession() {
                sessions.get().close();
                sessions.set(null);
        }

    public static Session currentSession() {
                return sessions.get();
        }

}